USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Permissions-Insert]    Script Date: [[20120914064958]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064958]]
-- Description:	Insert record into table [dbo].[Permissions]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Permissions-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Permissions-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Permissions-Insert]
	/*@Permission_RowNumber int =Null OUTPUT , 
	@Permission_ID uniqueidentifier =Null  , 
	@Permission_NameAr varchar(200) =Null  , 
	@Permission_NameEn varchar(200) =Null  , 
	@Permission_Search varchar(max) =Null  , 
	@Permission_TimeStamp timestamp =Null OUTPUT*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[Permissions](/*[Permission_ID], [Permission_NameAr], [Permission_NameEn], [Permission_Search]*/)
	VALUES     (/*@Permission_ID, @Permission_NameAr, @Permission_NameEn, @Permission_Search*/)

	/*SELECT @Permission_RowNumber = [Permission_RowNumber], @Permission_TimeStamp = [Permission_TimeStamp]
    FROM [dbo].[Permissions]
    WHERE  ( [Permission_ID] =@Permission_ID )
	AND  ( [Permission_NameAr] =@Permission_NameAr )
	AND  ( [Permission_NameEn] =@Permission_NameEn )
	AND  ( [Permission_Search] =@Permission_Search )*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Permissions-update]    Script Date: [[20120914064958]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064958]]
-- Description:	Update record in table [dbo].[Permissions]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Permissions-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Permissions-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Permissions-update]
	/*@Permission_RowNumber int =Null OUTPUT , 
	@Permission_ID uniqueidentifier =Null  , 
	@Permission_NameAr varchar(200) =Null  , 
	@Permission_NameEn varchar(200) =Null  , 
	@Permission_Search varchar(max) =Null  , 
	@Permission_TimeStamp timestamp =Null OUTPUT , 
	@OldTimeStamp timeStamp OUTPUT*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/*SELECT @OldTimeStamp = [Permission_TimeStamp]
    FROM [dbo].[Permissions]
    	WHERE ([Permission_ID] = @Permission_ID)

    IF  @OldTimeStamp = @Permission_TimeStamp
    BEGIN*/
		Update [dbo].[Permissions] SET 
		/*[Permission_ID] =@Permission_ID, 
		[Permission_NameAr] =@Permission_NameAr, 
		[Permission_NameEn] =@Permission_NameEn, 
		[Permission_Search] =@Permission_Search*/
		/*WHERE ([Permission_ID] = @Permission_ID)*/
	/*END*/

	/*SELECT @Permission_RowNumber = [Permission_RowNumber], @Permission_TimeStamp = [Permission_TimeStamp]
    FROM [dbo].[Permissions]
	WHERE ([Permission_ID] = @Permission_ID)*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Permissions-Insert-Update]    Script Date: [[20120914064958]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064958]]
-- Description:	Insert OR Update record into table [dbo].[Permissions]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Permissions-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Permissions-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Permissions-Insert-Update]
	/*@Permission_RowNumber int =Null OUTPUT , 
	@Permission_ID uniqueidentifier =Null  , 
	@Permission_NameAr varchar(200) =Null  , 
	@Permission_NameEn varchar(200) =Null  , 
	@Permission_Search varchar(max) =Null  , 
	@Permission_TimeStamp timestamp =Null OUTPUT , 
	@Inserted bit OUTPUT , 
	@OldTimeStamp timeStamp OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[Permissions] 
					/*WHERE ([Permission_ID] = @Permission_ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[Permissions](/*[Permission_ID], [Permission_NameAr], [Permission_NameEn], [Permission_Search]*/)
		VALUES     (/*@Permission_ID, @Permission_NameAr, @Permission_NameEn, @Permission_Search*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/*SELECT @OldTimeStamp = [Permission_TimeStamp]
		FROM [dbo].[Permissions]
    	WHERE ([Permission_ID] = @Permission_ID)

		IF  @OldTimeStamp = @Permission_TimeStamp
		BEGIN*/
			Update [dbo].[Permissions] SET 
			/*[Permission_ID] =@Permission_ID, 
			[Permission_NameAr] =@Permission_NameAr, 
			[Permission_NameEn] =@Permission_NameEn, 
			[Permission_Search] =@Permission_Search*/
			/*WHERE ([Permission_ID] = @Permission_ID)*/
		/*END*/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @Permission_RowNumber = [Permission_RowNumber], @Permission_TimeStamp = [Permission_TimeStamp]
    FROM [dbo].[Permissions]
	WHERE ([Permission_ID] = @Permission_ID)*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Permissions-Delete]    Script Date: [[20120914064958]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064958]]
-- Description:	delete records from table [dbo].[Permissions] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Permissions-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Permissions-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Permissions-Delete]
	/*@Permission_RowNumber int =null  , 
	@Permission_ID uniqueidentifier =null  , 
	@Permission_NameAr varchar(200) =null  , 
	@Permission_NameEn varchar(200) =null  , 
	@Permission_Search varchar(max) =null  , 
	@Permission_TimeStamp timestamp =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[Permissions]
	WHERE /*( [Permission_RowNumber] = ISNULL(@Permission_RowNumber, [Permission_RowNumber]) )
	AND ( [Permission_ID] = ISNULL(@Permission_ID, [Permission_ID]) )
	AND ( [Permission_NameAr] like ISNULL(@Permission_NameAr, [Permission_NameAr]) )
	AND ( [Permission_NameEn] like ISNULL(@Permission_NameEn, [Permission_NameEn]) )
	AND ( [Permission_Search] like ISNULL(@Permission_Search, [Permission_Search]) )
	AND ( [Permission_TimeStamp] = ISNULL(@Permission_TimeStamp, [Permission_TimeStamp]) )*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Permissions-Select]    Script Date: [[20120914064958]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064958]]
-- Description:	select records from table [dbo].[Permissions] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Permissions-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Permissions-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Permissions-Select]
	/*@Permission_RowNumber int =null  , 
	@Permission_ID uniqueidentifier =null  , 
	@Permission_NameAr varchar(200) =null  , 
	@Permission_NameEn varchar(200) =null  , 
	@Permission_Search varchar(max) =null  , 
	@Permission_TimeStamp timestamp =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[Permissions]
	WHERE /*( [Permission_RowNumber] = ISNULL(@Permission_RowNumber, [Permission_RowNumber]) )
	AND ( [Permission_ID] = ISNULL(@Permission_ID, [Permission_ID]) )
	AND ( [Permission_NameAr] like ISNULL(@Permission_NameAr, [Permission_NameAr]) )
	AND ( [Permission_NameEn] like ISNULL(@Permission_NameEn, [Permission_NameEn]) )
	AND ( [Permission_Search] like ISNULL(@Permission_Search, [Permission_Search]) )
	AND ( [Permission_TimeStamp] = ISNULL(@Permission_TimeStamp, [Permission_TimeStamp]) )*/
END
GO
-- =============================================
